import React, {Component} from "react";
import {Table} from 'antd';

const DEFAULT_PAGE_SIZE = 10;
const DEFAULT_SIZE = 'middle';

class TableDefault extends Component {
  constructor (props) {
    super(props);
  }

  render () {
    let {pagination, indexColumn, columns} = this.props;

    pagination = Object.assign({
      showQuickJumper: true,
      showSizeChanger: true,
      showTotal: (total) => {
        return `共 ${total} 条记录`
      }
    }, pagination);

    let {current = 1, pageSize = DEFAULT_PAGE_SIZE} = pagination;
    let startIndex = (current - 1) * pageSize;

    // 显示序号列
    if (indexColumn) {
      columns = [{
        key: '__index',
        align: 'center',
        title: '序号',
        width: 100,
        render: (text, record, index) => {
          return index + startIndex + 1;
        }
      }, ...columns]
    }

    return (
      <React.Fragment>
        <Table  size={DEFAULT_SIZE} {...this.props} columns={columns} pagination={pagination}/>
      </React.Fragment>
    );
  }
}

export default TableDefault
